job "echo" {
  datacenters = ["dc1"] # 数据中心名称，根据实际环境修改

  group "echo" { # 必须将 group 定义为块（Block）
    count = 2 # 初始实例数

    network { # network 块需嵌套在 group 内
      port "http" {
        to = "9999"
      }
    }

    service { # service 块需嵌套在 group 内
      name = "api"
      tags = ["env=prod", "app=echo"]
      port = "http"

      check { # 健康检查块嵌套在 service 内
        type     = "http"
        path     = "/health"
        interval = "10s"
        timeout  = "2s"
      }
    }

    task "echo" { # task 块需嵌套在 group 内
      driver = "docker"
      env {
        CONSUL_ADDR = "10.1.12.4:8500"
      }

      config {
        image = "registry.cn-hangzhou.aliyuncs.com/my_public_images/echo:latest"
        ports = ["http"]
      }

      resources { # 资源配置嵌套在 task 内
        cpu    = 100 # MHz
        memory = 64 # MB
      }
    }
  }
}